package com.example.zx.theline.jclr.pub;

import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TextView;

import com.example.zx.theline.R;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import GsonBean.JcbAqfxListBean;
import GsonBean.JcbShdwListBean;
import GsonBean.JcxxChakanBean;
import Utils.MyToast;
import app.MyApplication;
import base.BaseActivity;
import dialog.ShcfDialog;
import network.BaseCallBack;
import network.NetWorkApi;
import network.ObjectHttpResponseHandler;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import views.LzxxItemView;

//检查详情 listview 查看页面  当jcbstatus！=0 为待处理状态 只能查看 显示该activity
public class JcxxChaKanActivity extends BaseActivity {


    //控制检查详情 layout visiavle
    RadioButton jcxx_button;

    //流转信息详情 layout visiavle
    RadioButton lzxx_button;

    //日计划编号
    String rjdjhbBh;

    //检查表ID
    String jdjhjcbId;

    //月度编号
    String ydbh;
    TextView ydbhtv;

    //信息类型
    TextView xxlx;

    //日计划号
    TextView rjhh;

    //类别
    TextView lb;

    //责任单位
    TextView zrdw;

    //施工单位
    TextView sgdw;

    //施工地点
    TextView sgdd;

    //施工项目
    TextView sgxm;

    //创建日期
    TextView jcrq;

    //创建人
    TextView jcr;

    //计划监护人
    TextView jhjhr;

    //录入人
    TextView lrr;

    //检查地点
    TextView jcdd;

    //风险列表
    LinearLayout fxlb;

    //整体评价
    TextView ztpj;

    //检查详情
    TextView jcqk;

    //保存草稿
    TextView bccg;

    //提交完成
    TextView tjwc;

    //取消录入
    TextView qxlr;

    //发现时间
    TextView fxsj;

    //通知时间
    TextView tzsj;

    //发令单位
    TextView fldw;

    //发令人
    TextView flr;

    //停工项目
    TextView tgxm;

    //复工项目
    TextView fgxm;

    //发现问题
    TextView fxwt;

    //整改情况
    TextView zgqk;

    TextView leftTextView;


    //整改情况layout
    LinearLayout zgqk_layout;

    LinearLayout wlxx;

    List<JcxxAddActivity.ZrdwData> SpinnerData;


    //收回重发
    TextView shcf;


    //停工项目layout
    LinearLayout tgxm_layout;

    //复工项目layout
    LinearLayout fgxm_layout;

    JcxxChakanBean mJcxxChakanBean;

    ScrollView lzxx_layout;
    ScrollView jcxx_layout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jcxx_cha_kan);
        InitView();
        InitData();
        InitListen();
    }

    @Override
    protected void InitView() {
        xxlx = (TextView) findViewById(R.id.xxlx);
        rjhh = (TextView) findViewById(R.id.rjhh);
        ydbhtv = (TextView) findViewById(R.id.ydbh);
        lb = (TextView) findViewById(R.id.lb);
        zrdw = (TextView) findViewById(R.id.zrdw);
        sgdw = (TextView) findViewById(R.id.sgdw);
        sgdd = (TextView) findViewById(R.id.sgdd);
        sgxm = (TextView) findViewById(R.id.sgxm);
        sgdd = (TextView) findViewById(R.id.sgdd);
        jcrq = (TextView) findViewById(R.id.jcrq);
        jcr = (TextView) findViewById(R.id.jcr);
        lrr = (TextView) findViewById(R.id.lrr);
        jcdd = (TextView) findViewById(R.id.jcdd);
        fxlb = (LinearLayout) findViewById(R.id.fxlb);
        ztpj = (TextView) findViewById(R.id.ztpj);
        jcqk = (TextView) findViewById(R.id.jcqk);
        jhjhr = (TextView) findViewById(R.id.jhjhr);
        bccg = (TextView) findViewById(R.id.bccg);
        qxlr = (TextView) findViewById(R.id.qxlr);
        wlxx = (LinearLayout) findViewById(R.id.lzxx);
        fxsj = (TextView) findViewById(R.id.fxsj);
        tzsj = (TextView) findViewById(R.id.tzsj);
        fldw = (TextView) findViewById(R.id.fldw);
        flr = (TextView) findViewById(R.id.flr);
        tgxm = (TextView) findViewById(R.id.tgxm);
        fgxm = (TextView) findViewById(R.id.fgxm);
        fxwt = (TextView) findViewById(R.id.fxwt);
        zgqk = (TextView) findViewById(R.id.zgqk);
        leftTextView = (TextView) findViewById(R.id.leftTextView);

        zgqk_layout = (LinearLayout) findViewById(R.id.zgqk_layout);
        tgxm_layout = (LinearLayout) findViewById(R.id.tgxm_layout);
        fgxm_layout = (LinearLayout) findViewById(R.id.fgxm_layout);
        jcxx_button = (RadioButton) findViewById(R.id.jcxx_button);
        lzxx_button = (RadioButton) findViewById(R.id.lzxx_button);

        lzxx_layout = (ScrollView) findViewById(R.id.lzxx_layout);
        jcxx_layout = (ScrollView) findViewById(R.id.jcxx_layout);

        shcf = (TextView) findViewById(R.id.shcf);
    }

    @Override
    protected void InitData() {
        lzxx_button.setChecked(true);
        Bundle mBundle = getIntent().getExtras();
        rjdjhbBh = mBundle.getString("rjdjhbBh");
        jdjhjcbId = mBundle.getString("jdjhjcbId");
        getInfo();
    }

    @Override
    protected void InitListen() {
        jcxx_button.setChecked(true);

        jcxx_button.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    jcxx_layout.setVisibility(View.VISIBLE);
                    lzxx_layout.setVisibility(View.GONE);
                }
            }
        });
        lzxx_button.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    lzxx_layout.setVisibility(View.VISIBLE);
                    jcxx_layout.setVisibility(View.GONE);
                }
            }
        });
        qxlr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                JcxxChaKanActivity.this.finish();
            }
        });


        //收回重发
        shcf.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShcfDialog mShcfDialog = new ShcfDialog(JcxxChaKanActivity.this, mJcxxChakanBean);
                mShcfDialog.show();

            }
        });

        leftTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 JcxxChaKanActivity.this.finish();
            }
        });
    }

    public void getInfo() {
        //日计划号：rjdjhbBh
        //监督计划表主键：jdjhjcbId
        //登录用户名：loginId
        //传三个参数
        MyApplication.ShowWaitDialog(this);
        Map<String,String> map=new HashMap<>();
        map.put("rjdjhbBh", rjdjhbBh);
        map.put("loginId", MyApplication.getmLoginUser().getUserDisplayName());
        map.put("jdjhjcbId", jdjhjcbId);
        NetWorkApi.getJcxxChakanList(map, new BaseCallBack<JcxxChakanBean>() {
                    @Override
                    public void Success(Call<JcxxChakanBean> call, Response<JcxxChakanBean> response) {
                        try {
                            MyApplication.HideWaitDialog();
                            mJcxxChakanBean = response.body();
                            ydbh = mJcxxChakanBean.getRjdjhbInfo().getYdbh();
                            xxlx.setText(mJcxxChakanBean.getRjdjhjcbInfo().getJcbtype());
                            rjhh.setText(mJcxxChakanBean.getRjdjhbInfo().getBh());
                            ydbhtv.setText(ydbh);
                            lb.setText(mJcxxChakanBean.getRjdjhbInfo().getLb());
                            zrdw.setText(mJcxxChakanBean.getRjdjhjcbInfo().getZrDwMc());
                            sgdw.setText(mJcxxChakanBean.getRjdjhbInfo().getSgdwmc());
                            sgdd.setText(mJcxxChakanBean.getRjdjhbInfo().getSgdd());
                            sgxm.setText(mJcxxChakanBean.getRjdjhbInfo().getXmmc());
                            sgdd.setText(mJcxxChakanBean.getRjdjhbInfo().getSgdd());
                            jcrq.setText(mJcxxChakanBean.getRjdjhjcbInfo().getJcrq());
                            jcr.setText(mJcxxChakanBean.getRjdjhjcbInfo().getJcrName());
                            lrr.setText(mJcxxChakanBean.getRjdjhjcbInfo().getLrrName());
                            jcdd.setText(mJcxxChakanBean.getRjdjhjcbInfo().getJcdd());
                            jhjhr.setText(mJcxxChakanBean.getRjdjhjcbInfo().getJhjhr());
                            fxsj.setText(mJcxxChakanBean.getRjdjhjcbInfo().getFxsj());
                            tzsj.setText(mJcxxChakanBean.getRjdjhjcbInfo().getTzsj());
                            fldw.setText(mJcxxChakanBean.getRjdjhjcbInfo().getFldw());
                            flr.setText(mJcxxChakanBean.getRjdjhjcbInfo().getFlrName());
                            fxwt.setText(mJcxxChakanBean.getRjdjhjcbInfo().getFxwt());

                            //只有有整改情况  才显示该内容

                            if (mJcxxChakanBean.getRjdjhjcbInfo().getZgqk() != null) {
                                zgqk_layout.setVisibility(View.VISIBLE);
                                zgqk.setText(mJcxxChakanBean.getRjdjhjcbInfo().getZgqk());
                            }

                            //只有停工项目 才显示该内容
                            if (mJcxxChakanBean.getRjdjhjcbInfo().getSfjytg() != null) {
                                if (mJcxxChakanBean.getRjdjhjcbInfo().getSfjytg().equals("1")) {
                                    tgxm_layout.setVisibility(View.VISIBLE);
                                    tgxm.setText(mJcxxChakanBean.getRjdjhjcbInfo().getTgxmmc());
                                }
                            }

                            //只有复工项目 才显示该内容
                            if (mJcxxChakanBean.getRjdjhjcbInfo().getFgXmMc() == null || mJcxxChakanBean.getRjdjhjcbInfo().getFgXmMc().equals("")) {
                                fgxm_layout.setVisibility(View.GONE);
                            } else {
                                fgxm.setText(mJcxxChakanBean.getRjdjhjcbInfo().getFgXmMc());
                                fgxm_layout.setVisibility(View.VISIBLE);
                            }

                            //安全风险list 填充
                            if (mJcxxChakanBean.getJcbAqfxList() != null) {
                                for (JcbAqfxListBean mBean : mJcxxChakanBean.getJcbAqfxList()) {
                                    View view = View.inflate(JcxxChaKanActivity.this, R.layout.fxlb_chakan, null);
                                    TextView aqfxnr = (TextView) view.findViewById(R.id.aqfxnr);
                                    TextView fxpj = (TextView) view.findViewById(R.id.fxpj);
                                    aqfxnr.setText(mBean.getAqfxnr());
                                    fxpj.setText(getAqfxnr(Integer.parseInt(mBean.getAqfxpj())));
                                    fxlb.addView(view);
                                }
                            }

                            ztpj.setText(mJcxxChakanBean.getRjdjhjcbInfo().getZtpj());
                            jcqk.setText(mJcxxChakanBean.getRjdjhjcbInfo().getJcqk());

                            //流转信息list 填充
                            if (mJcxxChakanBean.getJcbShdwList() != null) {
                                for (int j = 0; j < mJcxxChakanBean.getJcbShdwList().size(); j++) {
                                    JcbShdwListBean mBean = mJcxxChakanBean.getJcbShdwList().get(j);
                                    LzxxItemView mView = new LzxxItemView(JcxxChaKanActivity.this, mBean.getShrxx(), j);
                                    wlxx.addView(mView);
                                }
                            }

                            if (mJcxxChakanBean.getRjdjhjcbInfo().isIsJcbRetractBtnHide()) {
                                shcf.setVisibility(View.VISIBLE);
                            }

                        } catch (Exception e) {
                            MyToast.showFail();
                        }
                    }

                    @Override
                    public void Failure(Call<JcxxChakanBean> call, Throwable t) {
                        MyToast.showFail();
                    }

                    @Override
                    public void onFinally() {

                    }
                }
        );
    }

    private String getAqfxnr(int i){

        if(i==1)
            return "好";

        if(i==2)
            return "正常";

        if(i==3)
            return "基本正常";

        if(i==4)
            return "有问题";

        return "好";
    }
}
